<template>
  <vol-box
    :lazy="true"
    v-model="model"
    title="选择供货商"
    :height="400"
    :width="1200"
    :padding="5"
    :onModelClose="onModelClose"
  >
    <div>
      <client ref="client"></client>
    </div>
    <template #footer>
      <div>
        <el-button type="primary" size="small" @click="onSelect"
          >确认</el-button
        >
      </div>
    </template>
  </vol-box>
</template>
  <script>
import VolBox from "@/components/basic/VolBox.vue";
import client from "@/views/customerinfo/q_client/q_client.vue";
//这里使用的vue2语法，也可以写成vue3语法
export default {
  components: {
    "vol-box": VolBox,
    client,
  },
  data() {
    return {
      model: false,
    };
  },
  methods: {
    async onModelClose() {
      this.$refs.client.searchFormFields.Client_no = null;
      this.$refs.client.searchFormFields.Client_name = null;
      this.$refs.client.searchFormFields.Client_flag = null;
      this.$refs.client.searchFormFields.Region_no = null;
    },
    open() {
      this.model = true;
      // let setIntervalTiem = setInterval(() => {
      //   if (this.$refs.client) {
      //     clearInterval(setIntervalTiem);
      //     this.$refs.client.$refs.grid.search();
      //   }
      // }, 100);
    },

    onSelect() {
      let rowObj = this.$refs.client.$refs.grid.getSelectRows();
      if (!rowObj.length) {
        this.base.ElMessageFn("请选择一条数据") 
        return (this.model = true);
      }
      if (rowObj[0].Client_type != "1") {
        this.base.ElMessageFn("请选择供货商") 
      }
        let AuditStatusSome = rowObj.some((item) => item.AuditStatus != 1);
        if (AuditStatusSome) {
          this.base.ElMessageFn("请选择审核通过的信息","warning") 
          return;
        }
      this.$emit("parentCall", ($parent) => {
        $parent.editFormFields.Supplier = rowObj[0].Client_no;
      });
      this.onModelClose();
      return (this.model = false);
    },
  },
};
</script>